<%@page import="vlc.StreamContext"%>

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Video Camera Streaming</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">

<link rel="stylesheet" href="./css/style.css" />
<%
	String width, height;
	int videoSize;

	if ((width = request.getParameter("width")) == null) {
		if ((width = (String) session.getAttribute("videoWidth")) == null) {
			width = "800";
		}
	} else {
		session.setAttribute("videoWidth", width);
	}

	if ((height = request.getParameter("height")) == null) {
		if ((height = (String) session.getAttribute("videoHeight")) == null) {
			height = "600";
		}
	} else {
		session.setAttribute("videoHeight", height);
	}
%>
<script>
	function updateFields() {
		var index = document.videoForm.videoSize.selectedIndex;
		var size = document.videoForm.videoSize.options[index].text.split("x");

		document.videoForm.width.value = size[0];
		document.videoForm.height.value = size[1];
	}
</script>
</head>
<body>
	<div id="wrapper">
		<div id="wrapper_inner">
			<div id="toplinks">
				<div id="toplinks_inner">
					<ul>
						<%
							if (request.isUserInRole("VLCSA_Admin")) {
						%>
						<li><a href="adminTool.jsp">*Administrative-tool</a></li>
						<%
							}
						%>
						<li><a href="<%=request.getContextPath()%>/LogoutServlet">Log
								out</a></li>
					</ul>
					<div class="clearer">&nbsp;</div>
				</div>
			</div>
			<div class="clearer">&nbsp;</div>

			<div id="header">
				<div id="header_inner">
					<h1>
						<a href="index.jsp">VLCSA</a>
					</h1>
					<p>
						<span>Video Camera Streaming Application</span>
					</p>
					<%
						if (request.isUserInRole("VLCSA_Admin")) {
					%>
					<a href="adminTool.jsp">*Administrative-tool</a>&nbsp; &nbsp;
					<%
						} else if (!request.isUserInRole("VLCSA_User")) {
					%>
					<jsp:forward page="login.jsp" />
					<%
						}
					%>
					<a href="<%=request.getContextPath()%>/LogoutServlet">Log-out</a>
				</div>
			</div>
			<div id="main">
				<h1>Welcome to streaming page</h1>

				<div class="clearer">&nbsp;</div>

				<form method="get" action="index.jsp" name="videoForm">
					<table border=4>
						<tr>
							<td><label>VideoSize </label> <select name="videoSize"
								onchange="updateFields()">
									<option>Prefered size</option>
									<option>400x300</option>
									<option>600x400</option>
									<option>640x480</option>
									<option>800x600</option>
									<option>1024x768</option>
									<option>1280x1024</option>
							</select> <br /> <br /> <label>Width : <input type="text"
									name="width" value="<%out.print(width);%>" size="4"></label> <label>Height:
									<input type="text" name="height" value="<%out.print(height);%>"
									size="4">
							</label>
								<p Align="center">
									<br /> <input type="submit" value="Apply" style = "width:100%"/>
								</p></td>
							<td>
								<%
									if (StreamContext.getInstance().isPlaying()) {
										out.println(StreamContext.getInstance().getVideoComponent(
												width, height));
									} else {
										out.println("<p Align='center'>Currently no video is playing.</p>");
										out.println("<p Align='center'><br /><input type='submit' value='Reload page' /></p>");
									}
								%>
							</td>
						</tr>
					</table>
				</form>
				<div class="clearer">&nbsp;</div>
				<div id="footer">
					<div id="footer_inner">

						<div class="left">
							&copy; Centre hospitalier universitaire Sainte-Justine All rights
							reserved. <br />&copy; 2008 Website.com - Your Site Slogan
						</div>

						<div class="right">
							<a href="http://templates.arcsin.se/">Website template</a> by <a
								href="http://arcsin.se/">Arcsin</a>
						</div>

						<div class="clearer">&nbsp;</div>

					</div>
				</div>
			</div>
		</div>
	</div>


</body>
</html>
